#include "pcd_write.h"
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

using std::string;

int pcd_write::Write()
{
	pcl::PointCloud<pcl::PointXYZ> cloud;

	// Fill in the cloud data
	cloud.width = 5;
	cloud.height = 1;
	cloud.is_dense = false;
	cloud.points.resize(cloud.width * cloud.height);

	for (auto& point : cloud)
	{
		point.x = 1024 * rand() / (RAND_MAX + 1.0f);
		point.y = 1024 * rand() / (RAND_MAX + 1.0f);
		point.z = 1024 * rand() / (RAND_MAX + 1.0f);
	}

	pcl::io::savePCDFileASCII("test_pcd9.pcd", cloud);
	std::cerr << "Saved " << cloud.size() << " data points to test_pcd.pcd." << std::endl;

	for (const auto& point : cloud)
		std::cerr << "    " << point.x << " " << point.y << " " << point.z << std::endl;
	system("pause");
	return (0);
}

int pcd_write::Write(string path)
{
	pcl::PointCloud<pcl::PointXYZ> cloud;

	// Fill in the cloud data
	cloud.width = 5;
	cloud.height = 1;
	cloud.is_dense = false;
	cloud.points.resize(cloud.width * cloud.height);

	for (auto& point : cloud)
	{
		point.x = 1024 * rand() / (RAND_MAX + 1.0f);
		point.y = 1024 * rand() / (RAND_MAX + 1.0f);
		point.z = 1024 * rand() / (RAND_MAX + 1.0f);
	}

	pcl::io::savePCDFileASCII(path, cloud);
	std::cerr << "Saved " << cloud.size() << " data points to test_pcd.pcd." << std::endl;

	for (const auto& point : cloud)
		std::cerr << "    " << point.x << " " << point.y << " " << point.z << std::endl;
	system("pause");
	return (0);
}
